window.onload=function (){

    document.getElementById('buttonHandle').onclick=function (){

        var tbody=document.getElementById('tablelistbody');
        var caterringFormNum=16;
        var checkedTobillList=[];
        var now=new Date();
        var dataInfo={};
        var stayristerid=document.getElementById("rm").value;
        axios({
            method: 'get',
            url: '/CommodityController/transRoomNumToStayRister/'+stayristerid,
        }).then(function (resp) {
            stayristerid=resp.data.data;
            //TODO
            for (var i=0;i<caterringFormNum;i++){
                //判断多选框是否被选中
                if (tbody.children[i].children[0].firstElementChild.checked==true){
                    // TODO
                    dataInfo={
                        "StayRegisterID":stayristerid,
                        "CommodityID":i+1,
                        "consumptionNumber":tbody.children[i].children[4].firstElementChild.value,
                        "consumptionMoney":parseFloat(tbody.children[i].lastElementChild.innerHTML),
                        "consumptionTime":now.getFullYear()+'-'+(now.getMonth()+1)+'-'+now.getDate()
                    };
                    checkedTobillList.push(dataInfo);
                }
            }
            //将checkedTobillList提交
            //console.log(checkedTobillList);
            var count=0;
            for (var i=0;i<checkedTobillList.length;i++){
                axios({
                    method: 'post',
                    url: '/CommodityController/insertBill',
                    data: checkedTobillList[i]
                }).then(function (resp) {
                    //console.log(i+1+'完成');
                    count++;
                    if (count==1){
                        alert('订餐完成！');
                        window.location.reload();
                    }
                });
            }
        });
    }

}